package com.example.hotel_lxy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.hotel_lxy.R;
import com.example.hotel_lxy.bean.BeanDate;

import java.util.List;

public class RVAdapter extends RecyclerView.Adapter<RVAdapter.ViewHolder> {

    private Context context;
    private List<BeanDate> data;
    private int type;
    private  RVAdapter2  rvAdapter2;
    public RVAdapter(Context context, List<BeanDate> data,int type){
        this.context = context;
        this.data = data;
        this.type=type;
    }

    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_rv,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        holder.name.setText(data.get(position).getTitle());
        holder.recyclerview2.setLayoutManager(new GridLayoutManager(context,7));
        rvAdapter2=new RVAdapter2(context,data.get(position).getMlist(),data.get(position).getTitle(),type);
        holder.recyclerview2.setAdapter(rvAdapter2);
        rvAdapter2.setOnDeleteListener(new OnDeleteListener() {
            @Override
            public void delete(String position) {
                String s1,s2;
                String[] split = position.split("-");
                if(Integer.valueOf(split[1])<10){
                    s1="0"+split[1];
                }else{
                    s1=split[1];
                }
                if(Integer.valueOf(split[2])<10){
                    s2="0"+split[2];
                }else{
                    s2=split[2];
                }
                mOnDeleteListener.delete(split[0]+"-"+s1+"-"+s2);
            }
        });

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{

        private TextView name;
        private RecyclerView recyclerview2;
        public ViewHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.name);
            recyclerview2=itemView.findViewById(R.id.recyclerview2);
        }
    }

    public interface OnDeleteListener{
        void delete(String position);
    }
    //声明接口对象
    private OnDeleteListener mOnDeleteListener;

    //设置监听器,实例化接口
    public void setOnDeleteListener(OnDeleteListener onDeleteListener){
        mOnDeleteListener = onDeleteListener;
    }

}

